﻿// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_SEC_QUERYFIELD
// * CreateDate    : 2011/7/12 12:42:33
// * Creater       : CodeSmith
// * LastChangeDate: 2011/7/12 12:42:33
// * LastChanger   : 2011/7/12 12:42:33
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Sec
{
    /// <summary>
    /// SecQueryfield
    /// </summary>
    public partial class SecQueryfieldBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objSecQueryfieldEntity">Entity</param>
        /// <returns>Entity</returns>
        public static SecQueryfieldEntity GetSecQueryfield(SecQueryfieldEntity objSecQueryfieldEntity)
        {
            return DataAccess.SelectSingle<SecQueryfieldEntity>(objSecQueryfieldEntity);
        }
        public static SecQueryfieldEntity GetSecQueryfieldByID(string menuID,int fieldOrder)
        {
            if (string.IsNullOrEmpty(menuID) || fieldOrder < 0)
            {
                return null;
            }
            SecQueryfieldEntity entity = new SecQueryfieldEntity();
            entity.MenuId = menuID;
            entity.Fieldorder = fieldOrder;
            return DataAccess.SelectSingle<SecQueryfieldEntity>(entity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objSecQueryfieldEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertSecQueryfield(SecQueryfieldEntity objSecQueryfieldEntity)
        {
            return DataAccess.Insert(objSecQueryfieldEntity);
        }

        public static bool InsertSecQueryfield(List<SecQueryfieldEntity> objSecQueryfieldEntityList)
        {
            return DataAccess.Insert(objSecQueryfieldEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objSecQueryfieldEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateSecQueryfield(SecQueryfieldEntity objSecQueryfieldEntity)
        {
            return DataAccess.Update(objSecQueryfieldEntity);
        }

        public static bool UpdateSecQueryfield(List<SecQueryfieldEntity> objSecQueryfieldEntityList)
        {
            return DataAccess.Update<SecQueryfieldEntity>(objSecQueryfieldEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objSecQueryfieldEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteSecQueryfield(SecQueryfieldEntity objSecQueryfieldEntity)
        {
            return DataAccess.Delete(objSecQueryfieldEntity);
        }

        public static bool DeleteSecQueryfield(List<SecQueryfieldEntity> objSecQueryfieldEntityList)
        {
            return DataAccess.Delete<SecQueryfieldEntity>(objSecQueryfieldEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetQueryFieldAll()
        {
            return DataAccess.SelectAllDataSet<SecQueryfieldEntity>();
        }
        public static DataSet GetQueryField(string menuID)
        {
            string sql = "SELECT * FROM SEC_QUERYFIELD ";
            if (string.IsNullOrEmpty(menuID) == false)
            {
                sql = @"SELECT Q.* FROM SEC_QUERYFIELD Q
                        INNER JOIN SEC_MENU C ON C.MENU_ID = Q.MENU_ID
                        LEFT JOIN SEC_MENU P1 ON P1.MENU_ID = C.PARENT_MENU
                        LEFT JOIN SEC_MENU P2 ON P2.MENU_ID = P1.PARENT_MENU
                        WHERE C.MENU_ID = '" + menuID + "' OR P1.MENU_ID = '" + menuID + "' OR P2.MENU_ID = '" + menuID + "'";
            }
            return DataAccess.SelectDataSet(sql);
        }
        #endregion

        #region Functions
        public static DataSet QueryField(string menuID, string IsCommon)
        {
            string strSql = @"SELECT FIELDTEXT,FIELDVALUE FROM SEC_QUERYFIELD WHERE MENU_ID='" + menuID + "'";

            if (!string.IsNullOrEmpty(IsCommon))
            {
                strSql += "AND ISCOMMONUSED='" + IsCommon + "'";
            }
            strSql += "   ORDER BY FIELDORDER";

            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                DataSet ds = broker.FillSQLDataSet(strSql);
                if (ds != null && ds.Tables.Count > 0)
                    return ds;
                else
                    return null;
            }
        }
        #endregion
    }


}

